<?php $this->headStyle()->captureStart()?>
    #content td { padding:5px}
    #content table { border:1px #aaa solid; padding:5px; width:100%}
    #content th {font-weight:bold;}
    #content input {width:140px}
<?php $this->headStyle()->captureEnd()?>

<?php $this->JQuery()->javascriptCaptureStart() ?>
$j(document).ready(function() {
    $j('#listings input[type="text"]').each(function() {
        $j(this).blur(function() {
            if ($j(this).attr('prev') !== $j(this).attr('value')) {
                $j.post(
                    '<?php echo $this->geturl('edit','listingAttribute', null, 'admin1')?>',
                    //{id:$j(this).attr('rel'), val:$j(this).attr('value'), loc:$j(this).attr('locale')}
                    $j(this).parent().parent().find(":input").serializeArray()
                );
            }
        });
    });
});
<?php $this->JQuery()->javascriptCaptureEnd() ?>

<table class="actions">
    <tr>
        <td>
            <a href="<?php echo $this->geturl('delete-make','listingAttribute', null, 'admin1', array('id'=> $this->attribute->_id))?>">Delete</a>
        </td>
    </tr>
</table>

<table id="attribute">
    <tr>
        <th>Name</th>
        <td><?php echo $this->attribute->name?></td>
    </tr>
    <tr>
        <th>Type</th>
        <td><?php echo $this->attribute->type?></td>
    </tr>  
</table>

<table border="1" id="listings-add">
    <tr><th colspan="2">
        <form method="get" name="model_form" action="<?php echo $this->geturl('addmodel','listingAttribute', null, 'admin1')?>">
            Add a Model <br>
            Name EN: <input type="text" name="name_en" id="name_en" value=""/>
            Name TC: <input type="text" name="name_tc" id="name_tc" value=""/><br>
            Name SC: <input type="text" name="name_sc" id="name_sc" value=""/>
            Pinyin:  <input type="text" name="pinyin" id="pinyin" value=""/><br>
            Order:
            <select name="order" id="order" value="">
                <option value="1000">1000</option>
                <option value="1001">1001</option>
            </form>
            <input type="hidden" name="id" id="id" value="<?php echo $_GET['id'];?>"/>
            <input type="submit" name="add" id="add" value="Add"/>
        </form>
    </th></tr>
</table>
    
<?php $data  = Model_Listing_Attribute::all(array('path' => new MongoId($this->attribute->_id)))->sort(array('or' => 1, 'nm_en' => 1)); ?>
<?php $count = $data->count();?>
<?php if ($count != 0):?>
<table border="1" id="listings">
    <tr>
        <th style="width:50px">Action</th>    
        <th>Models (<?php echo $count?>)</th>
        <th>Position</th>
        <th>Tags</th>
        <th>status</th>
    </tr>
    <?php foreach ($data as $model):?>
    <tr>
        <td>
            <input type="hidden" name="id" value="<?php echo $model->_id?>">
            <a href="<?php echo $this->geturl('delete-model','listingAttribute', null, 'admin1', array('id'=> $model->_id))?>&idmake=<?php echo $this->attribute->_id?>">Delete</a>
        </td>
        <td>
            English: <input type="text" value="<?php echo htmlentities($model->name_en, ENT_COMPAT, 'utf-8'); ?>" name="name_en">
            TC: <input type="text" value="<?php echo htmlentities($model->name_tc, ENT_COMPAT, 'utf-8'); ?>" name="name_tc">
            SC: <input type="text" value="<?php echo htmlentities($model->name_sc, ENT_COMPAT, 'utf-8'); ?>" name="name_sc">
            py: <input type="text" value="<?php echo htmlentities($model->py, ENT_COMPAT, 'utf-8'); ?>" name="pinyin">
        </td>
        <td>
            <input type="text" value="<?php echo $model->order; ?>" name="order" id="order-<?php echo $model->_id?>" rel="<?php echo $model->_id?>">
        </td> 
        <td>
            <input type="text" value="<?php echo is_array($model->tags) ? implode(',',$model->tags) : ''; ?>" name="tags" id="tags-<?php echo $model->_id?>" rel="<?php echo $model->_id?>">
        </td> 
        <td id="status-<?php echo $model->_id?>" class="status"></td>
    </tr>
    <?php endforeach; ?>
</table>
<?php endif;?>
